from openpyxl import load_workbook
from openpyxl import Workbook
#将大写字母字段转化为小驼峰
def convert(string):

    string_list = str(string).split('_')
    first = string_list[0].lower()
    others = string_list[1:]

    others_capital = [word.capitalize() for word in others]

    others_capital[0:0] = [first]

    hump_string = ''.join(others_capital)
    return hump_string

def main():
    #设置excel文件目录
    excel_path = r'G:\横向课题\地质系统\我的任务\隐患点拓展表设计\隐患点拓展表接口文档版 (2).xlsx'
    #加载文件
    excel = load_workbook(excel_path)
    #设置excel文件的子表
    #table = excel.get_sheet_by_name(r'地面沉降与地裂缝')
    table = excel.worksheets[4]

    rows = table.max_row  # 获取行数
    cols = table.max_column  # 获取列数

    # 设置数据表中的数据名称列号
    cols_name = 1

    for i in range(2,rows+1):
        #获取指定单元格数据
        data = table.cell(row=i, column=cols_name).value
        if data==None:
            continue
        data_transfer=convert(data)
        #将转换后的字段覆盖原来字段
        table.cell(row=i, column=cols_name).value=data_transfer
    #保存修改
    excel.save(excel_path)


if __name__ == '__main__':
    main()